package com.dhl.controller;

import com.dhl.commonutils.jwt.JwtUtils;
import com.dhl.commonutils.R;
import com.dhl.entity.SysUser;
import com.dhl.service.SysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @title: LoginController
 * @Author danghailiang
 * @Date: 2022/9/23 17:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Resource
    private SysUserService sysUserService;

    @GetMapping("/list")
    @PreAuthorize(("hasAnyRole('ROLE_admin')"))
//    @PreAuthorize(("hasRole('ROLE_admin')"))
//    @PreAuthorize(("hasAnyAuthority('system:user1:resetPwd')"))
    public R list(@RequestHeader(required = false) String token) {
        List<SysUser> list = sysUserService.list();
        return R.ok().data("info", list);

    }

    @GetMapping("/login")
    public R login() {
        String token = JwtUtils.getJwtToken("1", "admin");
        return R.ok().data("token", token);
    }
}
